<template>
  <!-- 审核弹窗 -->
  <el-dialog title="审核订单" :visible.sync="isShow" center @close="close" append-to-body>
    <el-form :model="form" :rules="rules" ref="ruleForm">
      <el-form-item label="审核意见" prop="review">
        <el-input type="textarea" :rows="4" placeholder="请输入审核意见，通过无需输入。" v-model="form.review"></el-input>
      </el-form-item>
    </el-form>
    <div slot="footer" class="dialog-footer">
      <el-button type="danger" @click="submitForm('ruleForm','no')" v-no-more-click:3000>退 回</el-button>
      <el-button
        type="primary"
        @click="submitForm('ruleForm','yes')"
        :disabled="qualityFailed"
        v-no-more-click:3000
      >通 过</el-button>
    </div>
  </el-dialog>
</template>

<script>
export default {
  data() {
    return {
      isShow: false,
      form: {
        review: ""
      },
      rules: {
        review: [
          {
            // required: true,
            message: "请输入审批意见",
            trigger: "blur"
          }
        ]
      },
      order: null,
      qualityFailed: false
    };
  },
  methods: {
    close() {
      this.isShow = false;
      this.$refs["ruleForm"].resetFields();
    },
    show(val) {
      this.order = val.id;
      if (val.statuss[0].id == 5 || val.statuss[0].id == 15) {
        this.qualityFailed = true;
      } else {
        this.qualityFailed = false;
      }
      this.isShow = true;
    },
    submitForm(formName, pass) {
      this.$refs[formName].validate(valid => {
        if (valid) {
          let obj = {
            pass: pass,
            review: this.form.review
          };
          if (this.form.review == "" && pass == "yes") {
            obj.review = "过";
          }
          if (this.form.review == "" && pass == "no") {
            this.$message({
              type: "warning",
              message: "请输入审核意见"
            });
            return;
          }
          this.$axios
            .put(`/api/order/${this.order}/teacher_audit`, obj)
            .then(({ data }) => {
              if (data.status == "success") {
                this.$message.success("操作成功");
                // this.dialogFormVisible = false;

                // this.getTableData();
                // this.getMyinfo();
                this.close();
                this.$emit("refresh");
              } else {
                this.$message.error(data.message);
              }
            })
            .catch(err => {
              this.$message.error(err);
            });
        } else {
          return false;
        }
      });
    }
  }
};
</script>

<style>
</style>